package com.eco.utils;

import com.eco.constants.Constants;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;

/**
 * @author: xulinyu
 * @date: 2024/6/24 20:04  康奈德继电器方法
 */
@Slf4j
public class KndUtil {

    public static void sendCommand(String clientId, String command) {
        try{
            if (Constants.KND_TURN_ON.equals(command)) {
                command = Constants.ON_COMMAND_LIGHT;
            } else {
                command = Constants.OFF_COMMAND_LIGHT;
            }
            String msg = new String(command.getBytes(), "utf-8");
            ChannelHandlerContext ctx = NettyCtxMap.get(clientId);
            ctx.writeAndFlush(msg);
            log.info("向继电器[{}]发送指令[{}]成功", clientId, msg);
        }catch (Exception e){
            log.error(e.getMessage());
        }

    }


}
